package com.dmm.Exception;

import com.dmm.result.Result;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 统一异常处理类
 */

@ControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(value = Exceptionbean.class)
    @ResponseBody
    public Result error(Exceptionbean e){
        System.out.println(121);
        e.printStackTrace();
        System.out.println(e.getMessage());
        return Result.fail(null).message(e.getMessage()).code(e.getCode());
    }

    //全局异常处理
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return Result.fail(null).message("服务器内部错误");
    }
}